package com.tedu.rechargeOrder.controller;

import com.tedu.common.response.JsonResult;
import com.tedu.rechargeOrder.pojo.dto.RechargeOrderQuery;
import com.tedu.rechargeOrder.pojo.dto.RechargeOrderSavaParam;
import com.tedu.rechargeOrder.pojo.vo.RechargeOrderVO;
import com.tedu.rechargeOrder.service.RechargeOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@Api(tags = "订单模块")
@Slf4j
@RestController
@RequestMapping("/api/rechargeOrder")
public class RechargeOrderController {
    @Autowired
    RechargeOrderService orderService;
    @ApiOperation("查询充值订单")
    @GetMapping("select")
    public JsonResult selectRechargeOrder(RechargeOrderQuery query){
        log.debug("查询订单列表:orderQuery={}",query);
        List<RechargeOrderVO> list = orderService.selectOrder(query);
        return JsonResult.ok(list);
    }
    @ApiOperation("创建订单")
    @PostMapping("create")
    public JsonResult saveRechargeOrder(RechargeOrderSavaParam saveParam){



        if (saveParam.getOrderId()==null){

            log.debug("创建订单列表:OrderSaveParam={}",saveParam);
            orderService.create(saveParam);
        }else {
            log.debug("更新订单列表:OrderSaveParam={}",saveParam);
            orderService.update(saveParam);
        }
        return JsonResult.ok();
    }
    @ApiOperation("删除订单")
    @PostMapping("delete/{rechargeOrderId}")
    public JsonResult deleteOrderById(@PathVariable Long rechargeOrderId){
        log.debug("删除订单:deleteOrderById={}",rechargeOrderId);
        orderService.deleteById(rechargeOrderId);
        return JsonResult.ok();
    }

}
